package com.work.game.home.ui.activity;

import android.app.AlertDialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.BaseExpandableListAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.android.volley.Request;
import com.work.game.R;
import com.work.game.config.UrlConfig;
import com.work.game.home.ui.model.Good;
import com.work.game.home.ui.model.vo.BaseVo;
import com.work.game.volley.BaseActivity;
import com.work.game.volley.state.HUCState;

public class DeleteUserActivity extends BaseActivity {

    private CheckBox cbOk;
    private TextView tvWithdrawal;
    private AlertDialog alertDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_delete_user);
        super.onCreate(savedInstanceState);
        tvActionbarTitle.setText("注销账号");
    }

    @Override
    public void initView() {
        super.initView();
        cbOk = findViewById(R.id.cb_ok);
        tvWithdrawal = findViewById(R.id.tv_withdrawal);
    }

    @Override
    public void initClick() {
        super.initClick();
        tvWithdrawal.setOnClickListener(this);
        cbOk.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (!isChecked) {
                    tvWithdrawal.setTextColor(getResources().getColor(R.color.default_font_size));
                    tvWithdrawal.setBackgroundResource(R.drawable.radius_black_wite);
                } else {
                    tvWithdrawal.setTextColor(getResources().getColor(R.color.white));
                    tvWithdrawal.setBackgroundResource(R.drawable.radius_home);
                }
            }
        });
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.tv_withdrawal:
                if (!cbOk.isChecked()) {
                    showToast("请先阅读并同意勾选《重要提示》");
                    return;
                }
                showWithdraw();
                break;
        }
    }


    private void showWithdraw() {
        //判断提现账号
        AlertDialog.Builder dialog = new AlertDialog.Builder(this);
        // dialog.setTitle("绑定姓名");
        View root = LayoutInflater.from(this).inflate(R.layout.pop_delete, null);
        dialog.setView(root);

        root.findViewById(R.id.tv_ok).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sendLogout();
            }
        });
        root.findViewById(R.id.tv_no).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
            }
        });
        alertDialog = dialog.create();
        alertDialog.getWindow().setBackgroundDrawableResource(R.color.transparent);
        alertDialog.setCancelable(false);
        alertDialog.show();
    }

    @Override
    public void onSuccessfulStrType(int inputType, Object response) {
        super.onSuccessfulStrType(inputType, response);
        switch (inputType) {
            case HUCState.HUC_REQEUST_CODE_1:
                String str = (String) response;
                loadDismiss();
                showToast(str);
                setSharedPreferences("deviceId", "");
                finishAffinity();
                break;
        }
    }

    private void sendLogout() {
        loading();
        BaseVo baseVo = new BaseVo();
        baseVo.setToken(getSharedPreferences("deviceId"));
        hucRequestInterfase.executeStr(this, null, HUCState.HUC_REQEUST_CODE_1, Request.Method.POST, UrlConfig.URL_LOGOUT, hucParameInterfase.getRequestParameter(baseVo), true);
    }

}